/**************************************************************
 *@ProjectName: blweibo
 *@FileName: AccountListItemView.java
 *@Date: 2011-5-31
 *@Copyright: 2011 www.hrbanlv.com Inc. All rights reserved.
 **************************************************************/
package com.zhiweibo;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhiweibo.models.Account;

/**
 * The Class AccountListItemView.
 * 
 * @author SunHaibin
 * @since Android 1.6
 * @history 2011-5-31
 */
public class AccountListItemView extends LinearLayout implements OnClickListener {

    /** The Constant ITEM_EDIT_DELETE_NORMAL. */
    public static final int ITEM_EDIT_DELETE_NORMAL = 5;

    /** The Constant ITEM_EDIT_DELETE_SELECTED. */
    public static final int ITEM_EDIT_DELETE_SELECTED = 4;

    /** The Constant ITEM_NORMAL. */
    public static final int ITEM_NORMAL = 1;

    /** The Constant ITEM_SELECTED. */
    public static final int ITEM_SELECTED = 0;

    /** The context. */
    private Activity context;

    /** The delete btn. */
    private Button deleteBtn;

    /** The item position. */
    private int itemPosition;

    /** The handler. */
    private ListItemEventHandler handler;

    /** The point. */
    private ImageView point;

    /** The tv nick name. */
    private TextView tvNickName;

    /**
     * Instantiates a new account list item view.
     * 
     * @param paramActivity
     *            the param activity
     * @param paramAccount
     *            the param account
     * @param paramInt1
     *            the param int1
     * @param paramInt2
     *            the param int2
     * @param paramListItemEventHandler
     *            the param list item event handler
     */
    public AccountListItemView(Activity paramActivity, Account paramAccount, int paramInt1, int paramInt2,
            ListItemEventHandler paramListItemEventHandler) {
        super(paramActivity);
        context = paramActivity;
        itemPosition = paramInt1;
        handler = paramListItemEventHandler;
        LayoutInflater localLayoutInflater = (LayoutInflater) context.getSystemService("layout_inflater");
        switch (paramInt2) {
        case 2:
        case 3:
        default:
            break;
        case 0:
            localLayoutInflater.inflate(R.layout.accountlistitemview, this);
            ((ImageView) findViewById(R.id.ivPoint)).setImageDrawable(context.getResources().getDrawable(
                    R.drawable.green_point));
            break;
        case 1:
            localLayoutInflater.inflate(R.layout.accountlistitemview, this);
            break;
        case 5:
            localLayoutInflater.inflate(R.layout.accountlistitemeditview, this);
            point = (ImageView) findViewById(R.id.ivHighlightPoint);
            deleteBtn = (Button) findViewById(R.id.bnDelete);
            deleteBtn.setOnClickListener(this);
            break;
        case 4:
            localLayoutInflater.inflate(R.layout.accountlistitemeditview, this);
            point = (ImageView) findViewById(R.id.ivHighlightPoint);
            deleteBtn = (Button) findViewById(R.id.bnDelete);
            deleteBtn.setOnClickListener(this);
            point.setImageDrawable(context.getResources().getDrawable(R.drawable.green_point));
            break;
        }
        tvNickName = (TextView) findViewById(R.id.tvAccountName);
        tvNickName.setText(paramAccount.mNickName);
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.view.View.OnClickListener#onClick(android.view.View)
     */
    @Override
    public void onClick(View v) {
        if (v == deleteBtn) {
            handler.handleListItemEvent(0, itemPosition);
        }
    }
}